home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / SFS101S.ZIP / RO101.ZIP / RO_PROC.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  8KB  |  231 lines

  1. /********************************************************/
  2. /*                            */
  3. /*    ro_proc.c    various procedures for ro    */
  4. /*                            */
  5. /*    ro version 1.10                    */
  6. /*                            */
  7. /*    Portions copyright (c) 1989 by Ted A. Campbell    */
  8. /*        Bywater Software            */
  9. /*        P. O. Box 4023                */
  10. /*        Duke Station                */
  11. /*        Durham, NC    27706            */
  12. /*                            */
  13. /*    Contains portions of ROFF4, Version 1.60    */
  14. /*    (c) 1983, 4 by Ernest E. Bergmann        */
  15. /*        Physics, Building #16            */
  16. /*        Lehigh University            */
  17. /*        Bethlehem, Pa. 18015            */
  18. /*                            */
  19. /*    Contains portions of ROFF4, Version 1.61    */
  20. /*    (c) 1985 by Konrad Kwok                */
  21. /*        20 3rd Street, Section M        */
  22. /*        Fariview Park,                */
  23. /*        Hong Kong                */
  24. /*                            */
  25. /*    ro and its predecessor ROFF4 are based on     */
  26. /*    the ROFF text processor described in Kernigan    */
  27. /*    and Plauger's now-classic text <Software Tools> */
  28. /*                            */
  29. /* Permission is hereby granted for all commercial and    */
  30. /* non-commercial reproduction and distribution of this */
  31. /* material provided this notice is included.        */
  32. /*                            */
  33. /********************************************************/
  34.  
  35. #include "ro.h"
  36.  
  37. /**********************************************************
  38. Removes white-space characters at start of string.
  39. ***********************************************************/
  40.  
  41. skip_blanks ( string )
  42.    char *string;    /* cursor to original string */
  43.    {
  44.    char *p;    /* cursor to 'final' string */
  45.    for(p=string;*string==BLANK||*string==TAB||*string==NEWLINE;
  46.       string++);
  47.       while(*(p++) = *(string++));
  48.    }
  49.  
  50. /*************************************************************/
  51.  
  52. int comtyp (line)
  53.    char *line;
  54.    {
  55.    char let1, let2;
  56.    let1 = line[1];
  57.    let2 = line[2];
  58.  
  59.    if ( let1==COMMAND )      return( EM ); /* end macro or comment */
  60.    if ( let1=='f' && let2=='i')   return( FI ); /* fill            */
  61.    if ( let1=='t' && let2=='i')   return( TI ); /* temp. left indent    */
  62.    if ( let1=='b' && let2=='p')   return( BP ); /* break, page #         */
  63.    if ( let1=='b' && let2=='r')   return( BR ); /* break            */
  64.    if ( let1=='c' && let2=='e')   return( CE ); /* center line(s)         */
  65.    if ( let1=='i' && let2=='n')   return( IN ); /* left indent         */
  66.    if ( let1=='l' && let2=='l')   return( LL ); /* right margin         */
  67.    if ( let1=='l' && let2=='s')   return( LS ); /* line spacing         */
  68.    if ( let1=='n' && let2=='f')   return( NF ); /* no fill         */
  69.    if ( let1=='p' && let2=='l')   return( PL ); /* page length         */
  70.    if ( let1=='s' && let2=='p')   return( SP ); /* output blank lines   */
  71.    if ( let1=='n' && let2=='e')   return( NE ); /* need vertical spaces */
  72.    if ( let1=='t' && let2=='a')   return( TA ); /* tab size         */
  73.    if ( let1=='t' && let2=='c')   return( TC ); /* tab character         */
  74.    if ( let1=='t' && let2=='r')   return( TR ); /* translate chars      */
  75.    if ( let1=='a' && let2=='d')   return( AD ); /* adjust output lines  */
  76.    if ( let1=='n' && let2=='a')   return( NA ); /* no adjust output     */
  77.    if ( let1=='e' && let2=='m')   return( EM ); /* end macro         */
  78.    if ( let1=='d' && let2=='e')   return( DE ); /* define macro         */
  79.    if ( let1=='d' && let2=='s')   return( DS ); /* define string         */
  80.    if ( let1=='n' && let2=='r')   return( NR ); /* number register      */
  81.    if ( let1=='d' && let2=='i')   return( DI ); /* divert output         */
  82.    if ( let1=='s' && let2=='o')   return( SO ); /* source from file     */
  83.    if ( let1=='p' && let2=='m')   return( PM ); /* print macros         */
  84.    if ( let1=='e' && let2=='x')   return( EX ); /* exit (abort)         */
  85.    if ( let1=='i' && let2=='g')   return( IG ); /* ignore -- comment    */
  86.    if ( let1=='t' && let2=='m')   return( TM ); /* message to terminal  */
  87.    if ( let1=='f' && let2=='t')   return( FT ); /* set font         */
  88.    if ( let1=='p' && let2=='o')   return( PO ); /* page offset          */
  89.  
  90. #ifdef   NOTYET
  91.    if ( let1=='w' && let2=='h')   return( WH ); /* set trap          */
  92. #endif
  93.  
  94. #ifdef   NONROFF
  95.    if ( let1=='F' && let2=='O')   return( FO ); /* footer for title     */
  96.    if ( let1=='H' && let2=='E')   return( HE ); /* header for title     */
  97.    if ( let1=='S' && let2=='T')   return( ST ); /* stop between pages   */
  98.    if ( let1=='F' && let2=='F')   return( FF ); /* form feed         */
  99.    if ( let1=='S' && let2=='C')   return( SC ); /* space character      */
  100.    if ( let1=='O' && let2=='H')   return( OH ); /* odd-page header      */
  101.    if ( let1=='O' && let2=='F')   return( OF ); /* odd-page footer      */
  102.    if ( let1=='E' && let2=='H')   return( EH ); /* even-page header     */
  103.    if ( let1=='E' && let2=='F')   return( EF ); /* even-page footer     */
  104.    if ( let1=='C' && let2=='F')   return( CF ); /* trans. char. flag    */
  105.    if ( let1=='I' && let2=='C')   return( IC ); /* insert character     */
  106.    if ( let1=='B' && let2=='J')   return( BJ ); /* break, justified     */
  107.    if ( let1=='S' && let2=='S')    return( SS ); /* show strings */
  108.    if ( let1=='S' && let2=='R')    return( SR ); /* show registers    */
  109.    if ( let1=='M')
  110.       { 
  111.       if (let2=='1')      return( M1 );
  112.       if (let2=='2')      return( M2 );
  113.       if (let2=='3')      return( M3 );
  114.       if (let2=='4')      return( M4 );
  115.       }
  116.    if ( let1=='D' && let2=='B')   return( DB ); /* debug on          */
  117. #endif
  118.  
  119.    return( UNKNOWN );         /* no match */
  120.    }
  121.  
  122. /*************************************************************
  123. gets the number ( if any ) associated with any command 
  124. *************************************************************/
  125.  
  126. get_val( line, typ )
  127.    char *line;
  128.    int *typ;
  129.    {
  130.    int i;
  131.    char local[ MAXLINE ];
  132.    strcpy (local, line);    /* local copy */
  133.  
  134.    /* skip over the command line */
  135.    for(i=1; local[i]!=' '&&local[i]!='\t'&&local[i]!='\n'
  136.       &&local[i]!=0; i++);
  137.  
  138.    skip_blanks (&local[i]);      /* find the number */
  139.    *typ = local[i];      /* relative or absolute */
  140.    if ( *typ=='+' || *typ=='-' )
  141.       {
  142.       i++;
  143.       }
  144.    else if ( !isdigit( *typ ) )
  145.       {
  146.       return( NO_VAL );
  147.       }
  148.    return ( atoi( &local[i] ));
  149.    }
  150.  
  151. /*************************************************************
  152.  sets a non-stacked global parameter like ro_spval, ro_pagestop, etc.
  153.  Also checks that the new value is within the range of that 
  154.  parameter.   Assigns the default for that parameter if no value
  155.  is specified.
  156. *************************************************************/
  157.  
  158. set( param, val, arg_typ, defval, minval, maxval )
  159.    int *param, val, defval, minval, maxval;
  160.    int arg_typ;
  161.    {
  162.    if ( val == NO_VAL ) 
  163.       {
  164.       *param = defval;    /* defaulted */
  165.       }
  166.    else if (arg_typ == '+') 
  167.       {
  168.       *param += val;   /* relative + */
  169.       }
  170.    else if ( arg_typ == '-' ) 
  171.       {
  172.       *param -= val;   /* relative - */
  173.       }
  174.    else   
  175.       {
  176.       *param = val;          /* absolute */
  177.       }
  178.    *param = ro_min (*param, maxval);
  179.    *param = ro_max (*param, minval);
  180.  
  181. #ifdef   DEBUG
  182.    if ( ro_debug == TRUE ) 
  183.       {
  184.       fprintf( stderr, "DEBUG:  set() *param = %d\n", *param);
  185.       }
  186. #endif
  187.    }
  188.  
  189. /*************************************************************
  190.       end current filled line 
  191. **************************************************************/
  192.  
  193. ro_brk()
  194.    {
  195. #ifdef   DEBUG
  196.    if ( ro_debug == TRUE ) 
  197.       {
  198.       fprintf( stderr,"DEBUG:  ro_brk(): ro_outbuf=<%s>\n", ro_outbuf);
  199.       }
  200. #endif
  201.  
  202.    if ( ro_outpos )
  203.       {
  204.       put( ro_outbuf );
  205.       }
  206.    ro_outw = ro_outpos = ro_outtop = ro_outbot = ro_outwrds = 0;
  207.    ro_outbuf[0] = '\0';
  208.    }
  209.  
  210. /**************************************************/
  211.  
  212. initxu()      /*initialize underline,overstrike variables*/
  213.    {    
  214.    ro_xcol = ro_ucol = -1;
  215.    memfill(ro_xbuf,LSZ,' ');
  216.    memfill(ro_ubuf,LSZ,' ');
  217.    }
  218.  
  219. /****************************************/
  220.  
  221. need(n) /*test for space before footer*/
  222.    int n;   /*whole lines*/
  223.    {
  224.    if (( ro_vlineno >= (ro_bottom-n) ) && ( ro_bottom >= ro_vlineno ) )
  225.       {
  226.       do_space( HUGE );
  227.       ro_newpag = ++ro_curpag;
  228.       }
  229.    }
  230.  
  231.